﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Customer_Profile.Admin
{
    public partial class DataRightAdd : System.Web.UI.Page
    {
        protected static int FunctionId;
        protected static int lvl;
        protected void Page_Load(object sender, EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["ID"] != null)
                    FunctionId = Convert.ToInt32(Request.QueryString["ID"].ToString());
                else
                {
                    KVB.Common.JavaScript.ViewMsgGoUrl("MenuManage.aspx", "You Must Select");
                }
            }
        }

        protected void ibtnAdd_ServerClick(object sender, EventArgs e)
        {
            string name = txtName.Value;
            string mark = txtRemark.Value;
            string orderid = txtOrderid.Value;
            string lvlType = rType.SelectedValue;
            string use = drpUsed.SelectedValue;

            DataInfoEntity DataE = new DataInfoEntity();
            DataE.FunctionName = name;
            DataE.Mark = mark;
            DataE.LvlType = lvlType;
            DataE.Orderid = orderid;
            DataE.Used = use;


            Hashtable htDataInfo = new Hashtable();

            if (FunctionId == -1)
            {
                lvl = 0;
                DataE.ParentId = 0;
            }
            else
            {
                lvl = DataRightDao.getLvl(FunctionId);
                DataE.ParentId = FunctionId;
            }
            try
            {
                bool isSucess;
                if (FunctionId == -1)
                {
                    DataE.Lvl = 0;
                    htDataInfo.Add("DataInfo", DataE);
                    isSucess = DataRightDao.AddData(htDataInfo);
                }
                else
                {
                    DataE.Lvl = lvl + 1;
                    htDataInfo.Add("DataInfo", DataE);
                    isSucess = DataRightDao.AddData(htDataInfo);
                }
                if (isSucess == true)
                {
                    Response.Write("<script language=javascript>alert('Success!');</script>");

                    //记录用户操作日志
                    //CVOC.Comm.WriteSystemLog(Session["SS_USER_ID"].ToString(), Utility.ReplaceChar(Utility.ReplaceQuote(Request["menu_idx"].ToString()), true), "02", Page.Request.UserHostAddress, Page.Request.Path, "新增菜单操作，菜单名称为：" + txtName.Value);

                }
            }
            catch
            {
                Response.Write("<script language=javascript>alert('DataBase Is Wrong，Add Fail!');</script>");
            }
        }

        protected void ibtnBack_ServerClick(object sender, EventArgs e)
        {
            //Response.Redirect("MenuManage.aspx?menu_idx=" + Utility.ReplaceChar(Utility.ReplaceQuote(Request["menu_idx"].ToString()), true));
            Response.Redirect("DataAuthorityManage.aspx", true);
        }
    }
}
